////////////////////////////////////////////////////////////////////////////////
/// Name: rbuff.cpp
/// Author: B. Gian James  <gian@OpenHouseware.net>
/// Description: A ring dual, multi-level ring buffer for storing data from 
/// USART, network, etc.
///
// $Id: rbuff.cpp,v 1.2 2009/08/28 22:55:17 gian Exp $
#include "rbuff.h"

// Push onto the tail
void
RingBuff::Put(unsigned char c) volatile
{
	_buff[_tail++] = c;
	if (_tail >= _sz) _tail = 0;
	++_sz;
}

// Pop from the head
unsigned char
RingBuff::Get() volatile
{
	unsigned char c = _buff[_head++];
	if (_head >= _sz) _head = 0;
	--_sz;
	return c;
}


RingBuff::RingBuff()
{
	_buff = NULL;
	_head = _tail = _sz = 0;
}